package com.tagPack;

import com.entity.Admin;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

public class BannerTag extends SimpleTagSupport {
    public void doTag() throws JspException, IOException {
        JspWriter out = getJspContext().getOut();
        PageContext pageContext = (PageContext) getJspContext();
        Admin admin = (Admin) pageContext.getSession().getAttribute("admin");

        out.println("<div class=\"title fixed-top form-inline\" style=\"display: flex;\" >");
        out.println("<img src=\"/resources/images/logo.gif\" alt=\"logo\" style=\"height: 100%; max-width: 200px; min-width: 100px;\">");
        out.println("<div style=\"color: white;padding-bottom:10px;\">");
        out.println("<div class=\"col-1\">");
        out.println("</div>");

        if (admin == null){
            out.println("<h1 class=\"font-weight-bold\" style=\"color:white;\">您尚未登录 </h1>");
            out.println("<a href=\"http://localhost:8080/employee/login\" style=\"color: white;\" >普通员工登录</a>&nbsp|&nbsp<a href=\"http://localhost:8080/admin/login\" style=\"color: white;\" >管理员登录</a>");
        }
        else {
            out.println("<h1 class=\"font-weight-bold\" style=\"color:white;\">Welcome!&nbsp&nbsp" + admin.getUsername() + "</h1>");
            out.println("<a href=\"http://localhost:8080/admin/logout\" style=\"color: white;\">[退出]&nbsp&nbsp&nbsp&nbsp</a>");
            out.println("<a href=\"http://localhost:8080/admin/getDepartInfo\" style=\"color: white;\">&nbsp&nbsp&nbsp[首页]</a>");
        }

        out.println("</div>");
        out.println("</div>");
    }
}
